Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Refactor queries to allow for cascaded partial results #59

Merged
merged 18 commits into from
Sep 4, 2019

Conversation

kitten
Copy link
Member

@kitten kitten commented Sep 4, 2019

This builds upon #58 to allow us to cascade partial results upwards. The query logic has been simplified so uncached values are now handled in one place and are represented by undefined. The readSelection traverser can also early-return undefined when non-nullable fields are missing.

This means that non-cached entries cascade upwards until we find a nullable field or hit the root. Also, early returns are now everywhere, so we don't continue walking any query that is obviously incomplete.

The non-schema-aware mode hasn't changed in behaviour and we don't have any perf regressions 👍

benchmark run to show that perf is the same as before Screenshot 2019-09-04 at 20 55 02

This is to check whether a given type for
a list may have nullable entries.
First of all, this gets rid of `readOperation`, because
it's almost identical to `query`, which should save us
some bytes.

`readSelection` has been reimplemented. Instead of writing
fields onto data directly, it now first stores them in
`dataFieldValue`.

At any point when we encounter an uncached field that
is NOT nullable, we return undefined.
This is done by checking `dataFieldValue` against
the schema. This is now done in one place to save
some space and the hassle of reading repetitive code.

This works because we now represent uncached values
as `undefined`, which has been done in the past,
but has been removed. Hence:

- When `dataFieldValue` is `undefined` and a field
  is nullable then we write `null` and continue
- When `dataFieldValue` is `undefined` and a field
  is NOT nullable then we return `undefined` instead
  of `data` immediately
- Otherwise we write the field as usual

This is nice, because that means `undefined` cascades
upwards and this same logic also applies to resolved
links!
When no field has been set on Query and the result
would've been partially complete, then return
`undefined` for the entire Query.
@kitten kitten force-pushed the feat/cascading-nulls branch from ac5aa08 to a777d7d Compare September 4, 2019 18:18
@kitten kitten marked this pull request as ready for review September 4, 2019 19:40
@kitten kitten requested a review from JoviDeCroock September 4, 2019 19:40
Copy link

@JoviDeCroock JoviDeCroock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually amazing

src/operations/query.test.ts Outdated Show resolved Hide resolved
@kitten kitten merged commit 773c29b into master Sep 4, 2019
@kitten kitten deleted the feat/cascading-nulls branch September 4, 2019 20:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants